import os
import logging
from bodhi.web import *

def main(debug=False):
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG if debug else logging.INFO)

    from bodhi.routing import Mapper
    mapper = Mapper()

    mapper.connect("{filename}",
            constraints={'filename': r'favicon\.ico|robots\.txt'},
            defaults={'module': 'static', 'view': 'root_file'})

    mapper.connect('static/{*path}',
            name='static',
            defaults={'module': 'static', 'view': 'static_file'})

    mapper.connect('{module}/{view}/{id}',
            name='default',
            constraints={'id': r'\d+'},
            defaults={'module': 'home', 'view': 'index', 'id': None})

    modules = find_views(os.path.dirname(__file__), 'helloworld')

    app = Dispatcher(mapper, modules, debug=debug)

    from bodhi.servers import run
    if debug:
        run(app, autoreload=True, quiet=False)
    else:
        run(app)

if __name__ == '__main__':
    main(True)
